<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Administrator
 * Date: 13-10-30
 * Time: 上午10:34
 */
use pft\Member\MemberAccount;
use pft\Prod\Product;
use pft\Prod\Sale;
use pft\Prod\Ticket;

include '../common/autoload.php';
$mem = new MemberAccount($GLOBALS['le']);
$soap = SoapInit::GetSoapInside();
$ticket = new Ticket($GLOBALS['le']);
$a = $_GET['a'];
if($a=='notice') {
    $sql = "SELECT * from phone_tmp_info where id=2";
    $GLOBALS['le']->query($sql);
    $ts = array();
    while($r = $GLOBALS['le']->fetch_assoc() ){
        $ts[] = $r;
    }
    print_r($ts);
}
elseif($a=='prods') {
    $sql = "SELECT * FROM pft_d_operation_rec";
    $GLOBALS['le']->query($sql);
    while($r = $GLOBALS['le']->fetch_assoc()) {
        print_r($r);
    }
}
elseif($a=='chgmobile'){
//    $sql = "update pft_member set status=2 where id=54";
//    $GLOBALS['le']->query($str);
//    $m = $GLOBALS['le']->fetch_assoc();
//    print_r($m);
//SQL;
    $GLOBALS['le']->query($sql);
//    while($r=$GLOBALS['le']->fetch_assoc()) {
//        print_r($r);
//    }
}
elseif($a=='optisition') {
    $params['limit'] =170;
    $params['offset'] = 10;

    $count = "SELECT COUNT(*) FROM uu_products";
    $GLOBALS['le']->query($count);
    print_r($GLOBALS['le']->fetch_assoc());
    $time_start = microtime_float();
    $sql = <<<SQL
            SELECT t.id,t.landid,t.title as ticket_title,t.tprice,t.px,t.pay,
            t.storage,t.s_limit_up,t.s_limit_low,t.delaydays,t.ddays,t.getaddr,
            t.buy_limit_up,t.buy_limit_low,t.apply_did,t.pid,l.imgpath,
            l.id,l.title,l.area,l.address,l.jtype,l.addtime,l.terminal,
            l.taobao_support,l.passtime,l.salerid,l.px,l.status,l.topic,
            l.keywords,l.description,l.apply_did,l.p_type,l.attribute,m.dname,
            t.id as ticket_id,p.apply_limit,p.p_status,p.verify_op,p.verify_time
            FROM uu_jq_ticket t
            LEFT JOIN uu_products p ON p.id=t.pid
            LEFT JOIN uu_land l ON t.landid=l.id
            LEFT JOIN pft_member m ON m.id=t.apply_did
            INNER JOIN(
            SELECT p.id FROM uu_products p LEFT JOIN uu_land l ON l.id=p.contact_id LIMIT {$params['limit']},{$params['offset']}) pl
            ON pl.id=t.pid
SQL;
        $GLOBALS['le']->query($sql);
        $ret = array();
        while($r=$GLOBALS['le']->fetch_assoc()) {
            $ret[] = $r;
        }
    print_r($ret);
        $time_end = microtime_float();
        echo 'time_used:', ($time_end-$time_start);
//    $sql = "select * from uu_dist_apply where dtype=1 ORDER BY id DESC";
//    $GLOBALS['le']->query($sql);
//    while($r=$GLOBALS['le']->fetch_assoc()) {
//        print_r($r);
//    }
//    $sql = "SELECT * FROM pft_member WHERE account=200104";
//    print_r($GLOBALS['le']->fetch_assoc());
//    $sql="UPDATE pft_member SET account='200100' where id=316 LIMIT 1";
//    $GLOBALS['le']->query($sql);
//    echo 'affected_rows=' . mysql_affected_rows();
//    $sql = "SELECT * FROM pft_member where account<200000 AND dtype=1";
//    $GLOBALS['le']->query($sql);
//    while($r=$GLOBALS['le']->fetch_assoc()) {
//        print_r($r);
//    }

//    $sql = "SELECT account,cname,dname,id FROM pft_member WHERE dtype=0 ORDER BY account DESC";
//    $GLOBALS['le']->query($sql);
//    while($r=$GLOBALS['le']->fetch_assoc()) {
//        print_r($r);
//    }
//    echo mysql_affected_rows();
}
elseif($a=='getShip') {
    $sql_chk = "SELECT parent_id FROM pft_member_relationship WHERE".
        " son_id_type=3 AND son_id=105 AND ship_type=1";
    $GLOBALS['le']->query($sql_chk);
    while($r=$GLOBALS['le']->fetch_assoc()) {
        print_r($r);
    }
}
elseif($a=='emptyProducts') {
    $p = new Product($GLOBALS['le']);
    var_export($p->GetEmptyProduct());
}
elseif($a=='sale_lists') {
    $sql = "SELECT aid,pids FROM pft_product_sale_list WHERE fid=108";
    $GLOBALS['le']->query($sql);
    while($r = $GLOBALS['le']->fetch_assoc()) {
        print_r($r);
    }

    $GLOBALS['le']->query("select * from uu_products where id=90");
    while($r = $GLOBALS['le']->fetch_assoc()) {
        print_r($r);
    }
}
elseif($a=='set_mem_status') {
    var_dump( $mem->StatusSet(266, 1) );
}
elseif($a=='cmn') {
    $str ="UPDATE pft_member SET dtype=1 where id=316 LIMIT 1";
    $GLOBALS['le']->query($str);
}
elseif($a=='nte') {
    $sql = <<<SQL
        SELECT COUNT(*) as c FROM uu_notice_ext e
        LEFT JOIN uu_notice m ON m.id=e.nid
        WHERE e.did=3
        AND e.status=0
        AND m.status=1
SQL;
    $GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    echo $GLOBALS['le']->f('c');
}
elseif($a=='m') {
    echo $mem->ShowBalance(4,$soap);
    echo str_repeat('-',100);
}
elseif($a=='s') {
    print_r( $mem->GetSalerList('票付通') );
}
elseif($a=='ps') {
    $sql = "select * from pft_product_sale_list where aid=4";
    $GLOBALS['le']->query($sql);
    while($r = $GLOBALS['le']->fetch_assoc()) {
        print_r($r);
    }
}
elseif($a=="r") {
    //$str = "INSERT INTO pft_product_sale_list(fid,aid,pids) VALUES(52,70,'A')";
    //$GLOBALS['le']->query($str);
    $sql = "select id from pft_member where account='admin'";
    $GLOBALS['le']->query($sql);
    while($r = $GLOBALS['le']->fetch_assoc()) {
        print_r($r);
    }
   /* echo PHP_EOL;
    $sql = "SELECT id FROM  pft_member WHERE account='600028'";
    $GLOBALS['le']->query($sql);
    $GLOBALS['le']->fetch_assoc();
    $fid = $GLOBALS['le']->f('id');

    echo PHP_EOL . 'son:' .PHP_EOL;
    $str3 = "SELECT * FROM pft_member_relationship WHERE son_id=$fid";
    $GLOBALS['le']->query($str3);
    while( $r = $GLOBALS['le']->fetch_assoc() ) {
        print_r($r);
    }*/
}
elseif($a=='area') {
    $sql='SELECT `area_id`,`area_name` FROM `uu_area`';
    $araes = array();
    $GLOBALS['le']->query($sql);
    while($as = $GLOBALS['le']->fetch_assoc()) {
        $araes[$as['area_id']] = $as['area_name'];
    }
    var_export($araes);
}
elseif($a=='order') {
    include("OrderRecord.php");
    $order = new OrderRecord(100061,$soap);
    $orderDetail = $order->info();
    $a_orderInfoOut = (array)$orderDetail['mainOrder'];
    $a_orderInfoOut['successMsg'] = 'ok';
    $a_orderInfoOut['uuino'] = $uuino;
    print_r($orderDetail);

}
elseif($a=='verify') {
    $sql='SELECT * FROM `uu_prod_verify`';
    $araes = array();
    $GLOBALS['le']->query($sql);
    while($as = $GLOBALS['le']->fetch_assoc()) {
        $araes[] = $as;
    }
    var_export($araes);
}
elseif($a=='pc') {

    $pc = $ticket->ProductChanged(MemberAccount::BUYER, 3, 0);
    var_export($pc);
}
elseif($a=='co') {
    echo $ticket->CountTicketSale(24, $soap);
}
elseif($a=='upm') {
    $str = "SELECT fid,com_name FROM pft_member_extinfo";
    $fc = array();
    $GLOBALS['le']->query($str);
    while($r=$GLOBALS['le']->fetch_assoc()) {
        $fc[$r['fid']] = $r['com_name'];
    }
    var_export($fc);

    $str = "SELECT id,dname FROM pft_member";
    $fc = array();
    $GLOBALS['le']->query($str);
    while($r=$GLOBALS['le']->fetch_assoc()) {
        $fc[$r['id']] = $r['dname'];
    }
    var_export($fc);
}
elseif($a=='up') {
    $sql = "select * from pft_member where id =5";
    $GLOBALS['le']->query($sql);
    while($as = $GLOBALS['le']->fetch_assoc()) {
        $araes[] = $as;
    }
    var_export($araes);
}
//解除合作关系
elseif($a=='rmr') {
    var_export( $mem->removeRelation(4,54) );
}
elseif($a=='up_pft_rflex_id') {
    $pft_rflex_id = $_GET['pft_rflex_id'];
    $tid = $_GET['tid'];
    $sql_clear = "UPDATE uu_jq_ticket SET pft_rflex_id=$pft_rflex_id WHERE id=$tid";
    $GLOBALS['le']->query($sql_clear);
    echo 'ok';
}
elseif($a=='sale') {
    $saleObj = new Sale($GLOBALS['le'], 1);
    $res = $saleObj->GetProdsInfo(new Product($GLOBALS['le']), SoapInit::GetSoapInside());
    var_export($res);
}
elseif($a=='products') {
    $sql = "SELECT t.*,p.p_status,p.apply_limit FROM uu_jq_ticket t LEFT JOIN uu_products p ON p.id=t.pid where t.landid=31 AND p.apply_limit=1 AND p.p_status=0";
    $GLOBALS['le']->query($sql);
    while($r=$GLOBALS['le']->fetch_assoc()) {
        print_r($r);
    }
}
elseif($a=='price') {
    $GLOBALS['le']->query("select * from pft_member where mobile='15080463052' limit 1");
    print_r($GLOBALS['le']->fetch_assoc());
    var_dump($soap->get_Dynamic_Price_Merge(153,'2014-02-12',
        1,'','',1));
//    $result = $this->soap->get_Dynamic_Price_Merge($pid,$date,
//        $mode, $sdate, $edate, $ptype, $get_storage);
}
elseif($a=='order_search') {
    var_dump($soap->get_Dynamic_Price_Merge(153,'2014-02-15',
        1));
    $ifpack=1;
    $xml=$soap->Order_Globle_Search("","","","","","","","","","","","",114131,"","","","","",1,1,0,999,0,$stype,$payinfo,$pmode,$remotenum,$origin,$p_type,$order_confirm,$aid,$concat,$ifpack);
    echo $xml;
//    $simxml=simplexml_load_string($xml);
}
elseif($a=='dapply') {
//    $GLOBALS['le']->query("update uu_dist_apply SET status=0 WHERE id2>899");
//    $sql = "SELECT * FROM uu_dist_apply WHERE id2>899";
//    $GLOBALS['le']->query($sql);
//    while($r = $GLOBALS['le']->fetch_assoc()) {
//        print_r($r);
//    }
}
//$soap->PFT_Member_Fund_Modify(4, 4, 100, 1);
//echo $mem->ShowBalance(4,$soap);
exit;


exit;
//$up = "update uu_land SET status=1 where apply_did=4";
//$GLOBALS['le']->query($up);


$fid = $m['id'];
$str2 = "SELECT * FROM pft_member_extinfo WHERE fid=$fid";
$GLOBALS['le']->query($str2);
$me = $GLOBALS['le']->fetch_assoc();
print_r($me);

$str3 = "SELECT * FROM pft_member_relationship WHERE son_id=$fid";
$GLOBALS['le']->query($str3);
$mr = $GLOBALS['le']->fetch_assoc();
print_r($mr);
exit;
/*$str = "SELECT l.*,t.title as ticket_title FROM uu_land l LEFT JOIN uu_jq_ticket t on t.landid=l.id where l.apply_did={$_SESSION['memberID']}";
$GLOBALS['le']->query($str);
$ls = array();
while($r = $GLOBALS['le']->fetch_assoc() ){
    $ls[] = $r;
}
print_r($ls);*/
$str = "SELECT * FROM uu_jq_ticket LIMIT 100";
$GLOBALS['le']->query($str);
$ts = array();
while($r = $GLOBALS['le']->fetch_assoc() ){
    $ts[] = $r;
}
print_r($ts);
function microtime_float()
{
    list($usec, $sec) = explode(" ", microtime());
    return ((float)$usec + (float)$sec);
}



/*
$str = "SELECT * FROM uu_land_f LIMIT 10";
$GLOBALS['le']->query($str);
$lfs = array();
while($r = $GLOBALS['le']->fetch_assoc() ){
    $lfs[] = $r;
}
print_r($lfs);*/
//use pft\Prod\Product;
//use pft\Member\MemberAccount;

